package hephaestus.model.metamodel;

import java.util.Collection;
import java.util.Properties;

/**
 * 
 * @author $Leandro$
 * 
 */
public class TypeMapper {
	private Properties prop;

	public TypeMapper(Properties prop) {
		this.prop = prop;
	}

	/**
	 * 
	 * @param tList
	 */
	public void transformTypes(Collection<TypeableElement> tList) {
		if (tList != null) {
			for (TypeableElement t : tList) {
				t.setDefaultValue(this.mapDefaultValue(t.getType()
						.toLowerCase()
						+ "-default"));
				t.setType(this.mapType(t.getType()));
			}
		}
	}

	/**
	 * 
	 * @param type
	 * @return
	 */
	private String mapType(String type) {
		String newType = prop.getProperty(type.toLowerCase());
		if (newType == null) {
			return type;
		} else {
			return newType;
		}
	}

	/**
	 * 
	 * @param type
	 * @return
	 */
	private String mapDefaultValue(String type) {
		String newType = prop.getProperty(type.toLowerCase());
		if (newType == null) {
			return prop.getProperty("generic-default");
		} else {
			return newType;
		}
	}
}
